import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.List;

public class RedisListDemo {
    public static void main(String[] args) {
        JedisPool jedisPool = new JedisPool("tcp://127.0.0.1:8888");
        try (Jedis jedis = jedisPool.getResource()) {
            jedis.flushAll();
//            test1(jedis);
//            test2(jedis);
//            test3(jedis);
//            test4(jedis);
//            test5(jedis);
            test6(jedis);
        }
    }

    private static void test6(Jedis jedis) {
        System.out.println("llen");

        jedis.lpush("k1", "1", "2", "3", "4");
        System.out.println("len: " + jedis.llen("k1"));
    }

    private static void test5(Jedis jedis) {
        System.out.println("blpop");

        List<String> result = jedis.blpop(100, "k1", "k2");
        System.out.println("result[0]: " + result.get(0));
        System.out.println("result[1]: " + result.get(1));

    }

    private static void test4(Jedis jedis) {
        System.out.println("rpop");

        jedis.rpush("k1", "1", "2", "3");
        System.out.println("result: " + jedis.rpop("k1"));
        System.out.println("result: " + jedis.rpop("k1"));
        System.out.println("result: " + jedis.rpop("k1"));
        System.out.println("result: " + jedis.rpop("k1"));
    }

    private static void test3(Jedis jedis) {
        System.out.println("lpop");

        jedis.rpush("k1", "11", "22", "33");
        System.out.println("result: " + jedis.lpop("k1"));
        System.out.println("result: " + jedis.lpop("k1"));
        System.out.println("result: " + jedis.lpop("k1"));
        System.out.println("result: " + jedis.lpop("k1"));

    }

    private static void test2(Jedis jedis) {
        System.out.println("rpush");

        jedis.rpush("k1", "11", "22", "33", "44");
        System.out.println("values: " + jedis.lrange("k1", 0, -1));
    }

    private static void test1(Jedis jedis) {
        System.out.println("lpush and lrange");

        long result = jedis.lpush("k1", "11", "22", "33", "44");
        System.out.println("result: " + result);
        List<String> values = jedis.lrange("k1", 0, -1);
        System.out.println("values: " + values);
    }
}
